import 'dart:convert';
import 'package:cloud_medicine/components/util.dart';
import 'package:cloud_medicine/http/config.dart';
import 'package:dio/dio.dart';
import 'HttpUtil.dart';

Future getAddressList_api(String url) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    url,
    method: HttpUtil.GET,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

Future newAddress_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      method: HttpUtil.POST,
      headers: {'Authorization': token},
      parameters: data);
  return jsonDecode(res.data);
}

Future editAddress_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(url,
      parameters: data,
      method: HttpUtil.PUT,
      headers: {'Authorization': token});
  return jsonDecode(res.data);
}

Future deleteAddress_api(String url, Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    '$backIP/address',
    method: HttpUtil.DELETE,
    parameters: data,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}
